<?php

/**
 * this class provides functions for working with tooltips
 * @author		ungerboeck simon <su@militaerversand.at>
 *
 */
class Tooltip{
	private $tooltipContent = null;
	private $onShowFunc = null;
	private $onUpdateFunc = null;
	private $position = null;
	private $inlineContent = null;
	private $params = null;
	
	
	/************************************************************************
	 ************************** PUBLIC FUNCTIONS ****************************
	************************************************************************/
	
	public function __construct($inlineContent = null){
		$this->position = 'bottom';
		$this->inlineContent = $inlineContent;
		$this->params = array();
	}
	
	
	public function create(){
		$output = '<a ';
		$output .= isset($this->params)  ? $this->getParams() : '';
		$output .= 'href="#" class="easyui-tooltip" data-options="';
		$output .= 'position: \'' . $this->position . '\', ';
		$output .= 'content: ' . ((!isset($this->tooltipContent) ? '$(\'<div></div>\')' : ('\'' . $this->tooltipContent) . '\'')) . ',';
		$output .= (isset($this->onShowFunc) ? 'onShow: ' . $this->onShowFunc . ',' : '');
		$output .= (isset($this->onUpdateFunc) ? 'onUpdate: ' . $this->onUpdateFunc : '');
		$output .= '">' . $this->inlineContent . '</a>';
		return $output;
	}
	
	
	function __toString(){
		return $this->create();
	}
	
	
	public function addParam($param, $value){
		$this->params[$param] = $value;
	}
	
	
	
	/************************************************************************
	 **************************** GETTER / SETTER ***************************
	************************************************************************/
	
	public function setTooltipContent($content){
		$this->tooltipContent = $content;
	}
	
	public function setInlineContent($content){
		$this->inlineContent = $content;
	}
	
	public function setOnShowFunc($function){
		$this->onShowFunc = $function;
	}
	
	
	public function setOnUpdateFunc($function){
		$this->onUpdateFunc = $function;
	}
	
	public function setPosition($pos){
		$this->position = $pos;
	}
	

	
	
	/************************************************************************
	 ************************** PRIVATE FUNCTIONS ***************************
	************************************************************************/
	
	
	private function getParams(){
		$output = '';
		foreach($this->params as $param => $value)
			$output .= $param . '="' . $value . '" ';
		return $output;
	}
}